package tk.sunlatus.tools.secret;

public class EncodeThread implements Runnable {

    private EncoderUI ui = null;
    private SunlatusEncoder encoder = new SunlatusEncoder();
    private boolean encodeFlag = true;

    public void run() {
        String result = "";
        getUi().setResultText(result);
        if (getUi().isMessageDigestFlag()) {
            result = encoder.messageDigest(getUi().getDataText(), getUi().getAlgorithm());
        } else {
            if (encodeFlag) {
                result = encoder.encrypt(getUi().getDataText(), getUi().getPasswordText(), null);
            } else {
                result = encoder.decrypt(getUi().getDataText(), getUi().getPasswordText(), null);
            }
        }
        getUi().setResultText(result);
    }

    public void setUi(EncoderUI ui) {
        this.ui = ui;
    }

    public EncoderUI getUi() {
        return ui;
    }

    public void setEncodeFlag(boolean encodeFlag) {
        this.encodeFlag = encodeFlag;
    }

    public boolean isEncodeFlag() {
        return encodeFlag;
    }

}
